package com.my.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MyBatisUtil {
    public static SqlSession openSession(){
        String resource ="mybatis-config.xml";
        InputStream inputStream = null;
        SqlSession sqlSession=null;

        try{
            inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
            sqlSession = sqlSessionFactory.openSession();
    }catch (Exception e){
            e.printStackTrace();
        }
        return sqlSession;
    }
}



